C++密码破解

#include <iostream>
#include <string.h>
#include <stdlib.h>
void main()
{
    using namespace std;
    cout<<"请输入您的密码: ";
    char psw[100];
    cin.get(psw,100);
    int len = strlen(psw);
    char * ppsw = new char[len+1];
    for(int n=0;n<len+1;n++)
        ppsw[n]=0;
    cout<<"<<<逐个匹配>>>:\n";
    for(int i=0;i<len;i++)//最后一个空字符不用匹配
    {
        cout<<"破解进行中...匹配>>";
        for(int j=32;j<127;j++)
        {
            for(int m=0;m<5000000;m++);
            cout<<(char)j<<"\b";
            if(psw[i] == j)
            {
                ppsw[i]=j;
                cout<<"\n密码第 "<<i+1<<" 个字符为: "<<(char)j<<endl;
                break;
            }
        }
    }
    cout<<"\n破解成功!\n";
    cout<<"你的密码是:"<<ppsw<<endl;
    system("pause");
}
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
暴力破解NTLM加密算法需要对于每个可能的密码进行哈希计算,并将其与目标哈希进行比较。C++可以使用Windows API中的Cryptographic Service Provider (CSP)来实现NTLM哈希计算。以下是一个使用CSP进行NTLM哈希计算的示例代码: ```c++ #include <windows.h> #include <wincrypt.h> #include <iostream> #include <string> bool CrackNTLMHash(const std::string& hash, const std::string& charset, int length, std::string& password) { // Open a handle to the Microsoft Base Cryptographic Provider HCRYPTPROV hProv; if (!CryptAcquireContext(&hProv, nullptr, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { std::cerr << "Failed to acquire cryptographic context\n"; return false; } // Convert the hex-encoded hash to binary std::string hashBytes; for (size_t i = 0; i < hash.length(); i += 2) { hashBytes += static_cast<char>(std::stoi(hash.substr(i, 2), nullptr, 16)); } // Allocate a buffer for the hash object HCRYPTHASH hHash; if (!CryptCreateHash(hProv, CALG_MD4, 0, 0, &hHash)) { std::cerr << "Failed to create hash object\n"; CryptReleaseContext(hProv, 0); return false; } // Iterate over all possible passwords std::string passwordHash; for (int i = 0; i < length; ++i) { std::string password(length, charset[0]); do { // Hash the password if (!CryptHashData(hHash, reinterpret_cast<const BYTE*>(password.data()), length, 0)) { std::cerr << "Failed to hash data\n"; CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); return false; } // Get the hash value DWORD hashLength = 16; BYTE hashValue[16]; if (!CryptGetHashParam(hHash, HP_HASHVAL, hashValue, &hashLength, 0)) { std::cerr << "Failed to get hash value\n"; CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); return false; } // Compare the hash value to the target hash passwordHash.assign(reinterpret_cast<const char*>(hashValue), hashLength); if (passwordHash == hashBytes) { password = password.substr(0, i) + password[i] + password.substr(i + 1); break; } // Reset the hash object if (!CryptDestroyHash(hHash) || !CryptCreateHash(hProv, CALG_MD4, 0, 0, &hHash)) { std::cerr << "Failed to reset hash object\n"; CryptReleaseContext(hProv, 0); return false; } } while (std::next_permutation(password.begin(), password.end(), [&charset](char a, char b) { return charset.find(a) < charset.find(b); })); } // Release resources CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); // Check if the password was found if (passwordHash == hashBytes) { password = password.substr(0, length); return true; } else { return false; } } ``` 该代码将目标哈希作为十六进制字符串传递,因此您需要将其从NTLM哈希格式转换为十六进制字符串。此外,您需要为字符集和密码长度指定值。代码将在字符集中迭代所有可能的密码,并使用Cryptographic Service Provider计算NTLM哈希。如果找到密码,则将其保存在传递的字符串参数中并返回true,否则返回false。注意,这是一种非常低效的方法,因为它需要尝试所有可能的密码。在现实世界中,密码长度和复杂度通常足以使暴力破解成为不切实际的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值